package com.lqd.demo.springboot;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.lqd.demo.springboot.orm.dataJPA.bean.UserLoginLog;
import com.lqd.demo.springboot.orm.dataJPA.service.UserLoginLogService;

@RestController
public class DataJPAController {

	@Resource
	UserLoginLogService userLoginLogService ;
	
	@RequestMapping("/findByUserName")
	public UserLoginLog findUserLoginLog(String userName)
	{
		return userLoginLogService.findUserLoginLog(userName);
	}
	
	@RequestMapping("/findByMyUserName")
	public UserLoginLog findMyUserLoginLog(String userName)
	{
		return userLoginLogService.findMyUserLoginLog(userName);
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public UserLoginLog save(String userName)
	{
		UserLoginLog userLoginLog = new UserLoginLog();
		userLoginLog.setUsername("NIhao");
		userLoginLog.setSystemname("platform");
	    userLoginLogService.save(userLoginLog);
	    return userLoginLog ;
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public String save(int id)
	{
	    userLoginLogService.delete(id);
	    return "success" ;
	}
	
	@RequestMapping("/findPage")
	@ResponseBody
	public Iterable<UserLoginLog> findPage(int pageNo ,int pageSize)
	{
		return userLoginLogService.getAll(pageNo,pageSize);
	}
	
	@RequestMapping("/findPageOrderBy")
	@ResponseBody
	public Iterable<UserLoginLog> findPage(String orderby)
	{
		return userLoginLogService.getAll2(1,2,orderby);
	}
}
